<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Model\Assess;
use DB;
use Auth;

class AssessController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {   //评论详情
        $assess = DB::table('goods_assess')
                    ->join('users','goods_assess.uid', '=','users.id')
                    ->select('goods_assess.*','users.name')
                    ->paginate(4);
        //回复数量
        $count = Assess::count();
        //评价级别
        $level[0] = "好评";
        $level[1] = "中评";
        $level[2] = "差评";
        return view('admin.assess_index')->with('assess',$assess)->with('count',$count)->with('level',$level);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
    //单个删除
    public function del(Request $request){
        $id = $request['id'];
        return Assess::where('id',$id)->delete();
    }
    //批量删除 get传值 对值进行处理
    public function doDel(Request $request){
        $id = $request->id;
        $str = explode(",",$id);
        foreach($str as $v){
            DB::table('goods_assess')->where('id',"=","$v")->delete();
        }
            return  redirect("admin/assess");
        }
}
